PostgreSQL - how to insert row (column does not exist) [closed] - postgresql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I would never expect that I would need help with such a banal command:
INSERT INTO test (id, field1) VALUES (1, "dfds");
And result:
column dfds does not exist
LINE 1: INSERT INTO test (id, field1) VALUES (1, "dfds");;
^
SQL state: 42703
Character: 41
This is 200% correct SQL. 'dfds' is not any 'column' - this is value.
How to insert row in PGAdmin (GUI)? I click on 'view data' icon and no way to insert row.

String are quoted with ':
INSERT INTO test (id, field1) VALUES (1, 'dfds');
" is for identifiers.

Related

Perl: How to find total number of rows in a sqlite database without using max(rowid)? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I wanted to find out Number of Rows in a SQLITE database Table, i know that i can query using SELECT COUNT(*) FROM TABLENAME;
but i wanted to get the count using the perl code and store it into a variable? can i use the below code
my $stmt = qq(SELECT COUNT(*) AS $NUMBEROFROWS FROM TABLENAME)
$rv = $dbh->do($stmt);
OR
my $stmt = qq(SELECT COUNT(*) FROM TABLENAME
$NUMBEROFROWS = COUNT(*) );
$rv = $dbh->do($stmt);
Please suggest me how to count number of rows in SQLITE database table and store the value into a variable?
TIA
Perl variables aren't part of the SQL, you get the number from the database and populate the variable in Perl:
my ($count) = $dbh->selectrow_array('SELECT COUNT(1) FROM information');
print "$count\n";

Why developer used SELECT 1 IN PROCEDURE [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Why developer used SELECT 1 IN PROCEDURE? Is this something intended?
ALTER PROC [dbo].[AddCallerInVoiceComplaint]
#COMPNO VARCHAR(20),
#CALLERNAME VARCHAR(50),
#CALLERMOBILENO BIGINT,
#EMAILID varchar(50)
AS BEGIN
UPDATE VoiceComplaints
SET CallerName2 = #CALLERNAME,
CallerMobileNo2 = #CALLERMOBILENO,
CallerEmailid2 = #EMAILID
WHERE ComplaintNumber = #COMPNO
SELECT 1
END
The UPDATE statement doesn't generate a rowset as output, so there could be something looking for the 1 returned as a "update occured with no errors" signal

How to import a text file with '|' delimited data to PostgreSQL database? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a text file with | delimited data that I want to import to a table in PostgreSQL database. PgAdminIII only exports CSV files. I converted the file to a CSV file but still was unsuccessful importing data to PostgreSQL database. It says an error has occurred:
Extradata after last expected column.
CONTEXT: COPY <file1>, line1:
What I am doing wrong here?
Using the standard psql shell you can do this:
\copy table_name from 'filename' delimiter '|'
In the shell you can do
\h copy
to see more options and the complete syntax. Of course the manual about COPY is also worthwhile reading.

How to loop through a table and call a stored proc for each row? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a temp table with 10 values like this:
CREATE TABLE #RequireAuth (val1 int, val2 int /*, etc...*/ )
How can I call another stored proc that will take in these 10 values and return me back 6 values?
SELECT * FROM #RequireAuth -- Not sure how to call a SP from here?
I then need to take those 6 values and update a different table.
I've made some assumptions about your temp table because what you describe and what you show are different, but heres the base concept for a while loop.
CREATE TABLE #RequireAuth (val1 int, done bit default 0)
declare #varible int
,#count int
select #count =count(2) from #RequireAuth where done=0
while (#count>0)
BEGIn
select top 1 #varible=val1 from #RequireAuth where done=0
exec sp_YourProc #variable
update R set done=1 from #RequireAuth R where val1=#varible
select #count =count(2) from #RequireAuth where done=0
END

Why won't this SQL CAST work? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a nvarchar(50) column in a SQL Server 2000 table defined as follows:
TaskID nvarchar(50) NULL
I need to populate this column with random SQL GUID's using the NEWID() function (I am unable to change the column type to uniqueidentifier).
I tried this:
UPDATE TaskData SET TaskID = CAST(NEWID() AS nvarchar)
but I got the following error:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting
expression to data type nvarchar.
I also tried:
UPDATE TaskData SET TaskID = CAST(NEWID() AS nvarchar(50))
but then got this error:
Msg 8152, Level 16, State 6, Line 1
String or binary data would be
truncated.
I don't understand why this doesn't work but this does:
DECLARE #TaskID nvarchar(50)
SET #TaskID = CAST(NEW() AS nvarchar(50))
I also tried CONVERT(nvarchar, NEWID()) and CONVERT(nvarchar(50), NEWID()) but got the same errors.
Update:
Ok, my eyesight is going, the column size on the table is nvarchar(32) not 50. Deepest apologies for the timewasting and thanks for all the answers.
When you do not specify the size of your varchar/nvarchar during a cast or convert, it defaults to 30 characters. You need 36 characters to convert a guid to a string. That is why you get the error.
Either of these will work:
Select Cast(NewId() as nvarchar(36)), CONVERT(nvarchar(36), NEWID())
This test script works fine for me... I can only suggest that maybe your TaskId isn't an NVARCHAR(50) like you say? Try an sp_columns just to check...
CREATE Table #TaskData (TaskId NVARCHAR(50))
INSERT INTO #TaskData (TaskId) SELECT CONVERT(NVARCHAR(50), NEWID())
UPDATE #TaskData SET TaskId = CONVERT(NVARCHAR(50), NEWID())
DROP TABLE #TaskData
Please try the following cast:
CAST(NEWID() AS varchar(255))
use varchar data type, nvarchar needs double size