New answers tagged

1 vote
Accepted

How to copy data between postgres schemas if there are objects?

Cast the column to text and then to the desired type: CAST ( CAST (invoice_id_reseting_type AS text) AS invoice_reseting_type ) You have to list the columns instead of using * for that.
  • 36.9k
1 vote
Accepted

Unable to use result of a "subquery in select clause" in a "insert.. select.. on duplicate update" query

(SELECT 1) can be simplified to just 1. insert into t2 (c, d) select a, 1 as b1 from t1 on duplicate key update d = values(b1); The VALUES clause is 'wrong', change to insert into t2 ...
  • 71.6k
1 vote

Insert select - using selected value in ON DUPLICATE KEY UPDATE

It should be: ON DUPLICATE KEY UPDATE baz = VALUES(baz) When the query finds a duplicate and the ON DUPLICATE KEY UPDATE clause is activated, we can use the VALUES(x) syntax to get the values that ...
3 votes

Unable to use result of a "subquery in select clause" in a "insert.. select.. on duplicate update" query

insert into t2 (c, d) select a, (select 1) as b1 from t1 on duplicate key update d = t.b1; There are 2 tables in this query: t2 (in UPDATE clause) and t1 (in FROM clause). You refer to t.b1 - but ...
  • 18k
1 vote

OPENJSON Insert Select by Row

DECLARE @Json NVARCHAR(4000); DECLARE @AnotherTable TABLE ( [Value] NVARCHAR(10), Value1 NVARCHAR(10) ); SET @Json = N'{ "Test":[ { "Json1"...
1 vote

Incorrect datetime str_to_date INSERT SELECT

I did some tests trying to replicate your error, and managed to find "Warnings" instead, I'm not sure if this can lead to you finding the root cause but I hope this helps: I created a random ...
1 vote
Accepted

How to insert into table if all parameters are present & also if data has missing parameters?

You can specify default values for function arguments by appending DEFAULT and the desired value to the argument declaration: CREATE OR REPLACE FUNCTION insert_delivery( site_id integer DEFAULT ...
  • 1,372
0 votes
Accepted

Multiple Query Insert and Return

Perhaps instead of 2 separate insert statements, you can combine them with an UNION? Like INSERT INTO tile(mvt) SELECT ST_AsMVT(mvtgeom) FROM mvtgeom UNION ALL SELECT ST_AsMVT(mvtgeom1) FROM ...
  • 718
0 votes

Always Encrypted SQL Server : How to insert / updated using C++ code?

There was an issue in my SQLDriverConnect. It is now working. SQLHANDLE sqlenvhandle = 0; SQLHANDLE sqlconnectionhandle = 0; SQLHANDLE sqlstatementhandle = 0; SQLHANDLE sqlstatementhandle2 = 0; ...
0 votes

How to insert one record after every log record in PostgreSQL

Something like INSERT INTO logs (Start, Logname, End) SELECT End + INTERVAL '1 second', -- previous End + 1 second 'Idle', -- static literal value End + ...
  • 18k

Top 50 recent answers are included